package com.jt.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author li
 * 
 *         2014年11月12日
 *         
 *   * 多线程并发访问服务器
   * 
   * 每次http连接需要三次握手，开销很大，http/1.1默认支持连接复用；
   * 
   * PoolingHttpClientConnectionManager 允许管理器限制最大连接数 ，还允许每个路由器针对某个主机限制最大连接数。
   * 
   * 如下：setDefaultMaxPerRoute(3)之后，每次并发3个访问，所以打印输出是每次输出三个"test",验证了http连接管理器生效；
   * 
   *  清空失效连接：
   * 
   * 	连接的有效性检测是所有连接池都面临的一个通用问题，大部分HTTP服务器为了控制资源开销，并不会
    永久的维护一个长连接，而是一段时间就会关闭该连接。放回连接池的连接，如果在服务器端已经关闭，客
    户端是无法检测到这个状态变化而及时的关闭Socket的。这就造成了线程从连接池中获取的连接不一定是有效的。
    这个问题的一个解决方法就是在每次请求之前检查该连接是否已经存在了过长时间，可能已过期。
    但是这个方法会使得每次请求都增加额外的开销。HTTP Client4.0的ThreadSafeClientConnManager 提供了
    closeExpiredConnections()方法和closeIdleConnections()方法来解决该问题。
    前一个方法是清除连接池中所有过期的连接，至于连接什么时候过期可以设置，设置方法将在下面提到，
    而后一个方法则是关闭一定时间空闲的连接，可以使用一个单独的线程完成这个工作。
 */
public class HttpClient {
	private static Logger log = LoggerFactory.getLogger(HttpClient.class);
	private static final int CONNECT_TIME_OUT = 3 * 1000;// 连接超时时间
	private static final int SO_TIMEOUT = 65 * 1000; // 传输超时时间,因为有身份证读证,身份证读证超时时间为1分钟
	
    public static final int HTTP_MAX_CONNECTIONS = 200;
	
	private static PoolingHttpClientConnectionManager connManager = null;
	private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SO_TIMEOUT).setConnectTimeout(CONNECT_TIME_OUT).build();//设置请求和传输超时时间
	
	private static CloseableHttpClient client;
	public static IdleConnectionMonitorThread monitor;
	static {
		connManager = new PoolingHttpClientConnectionManager();
		//http://jinnianshilongnian.iteye.com/blog/2089792
		connManager.setMaxTotal(HTTP_MAX_CONNECTIONS);//设置整个连接池最大连接数 
		connManager.setDefaultMaxPerRoute(connManager.getMaxTotal());
		
		client = HttpClients.custom().setConnectionManager(connManager).build();
		monitor = new IdleConnectionMonitorThread(connManager);
		monitor.start();//启动线程，10秒钟清空一次失效连接
	}
	
	public static String doPost(String url) throws IOException {
		
		HttpPost httpPost = new HttpPost(url);
		httpPost.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		try {
			response = client.execute(httpPost);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}
		}catch (Exception e) {
			log.error(e.getMessage(), e);
		}finally{
			EntityUtils.consume(entity);
			httpPost.abort();
			if(response!=null){
				response.close();
			}
		}
		
		return null;
	}

	public static String doPost(String url, Map<String, Object> params) throws IOException {
		// log.info("url="+url+",params="+params.toString());
		HttpPost httpPost = new HttpPost(url);
		httpPost.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		try {
//			httpPost.addHeader("Host", new URI(url).getHost());
			
		    List <NameValuePair> nameValuePair = new ArrayList<NameValuePair>();  
			if (params != null && !params.isEmpty()) {
				for (String key : params.keySet()) {
					nameValuePair.add(new BasicNameValuePair(key, params.get(key).toString()));
				}
			}
		    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair,HTTP.UTF_8));  
		    
		    long startTime = System.currentTimeMillis();
			response = client.execute(httpPost);
			long endTime = System.currentTimeMillis();
			long t = endTime - startTime;
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}else{
				log.error("url="+url+",params="+params+",getStatusCode="+response.getStatusLine().getStatusCode());
			}
		}finally{
			try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			httpPost.abort();
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		
		return null;
	}
	
	public static String doPostForTeLaiDian(String url, String params,String token) throws IOException {
		
//		log.info("params="+params.toString());
		
		HttpPost httpPost = new HttpPost(url);
		httpPost.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		try {
			httpPost.addHeader("Authorization","Bearer " + token);//Bearer后有空格
		    httpPost.setEntity(new StringEntity(params,HTTP.UTF_8));  
		    
		    long startTime = System.currentTimeMillis();
			response = client.execute(httpPost);
			long endTime = System.currentTimeMillis();
			long t = endTime - startTime;
//			log.info("url="+url+" 耗时 过长： " + t  + "毫秒");
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}else{
				log.error("url="+url+",params="+params+",getStatusCode="+response.getStatusLine().getStatusCode());
			}
		}finally{
			try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			httpPost.abort();
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		
		return null;
	}

    public static String doPostForCDDZ(String url, String params,String token) throws IOException {
//		log.info("params="+params.toString());

        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(requestConfig);
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        try {
            httpPost.addHeader("Authorization","Bearer " + token);//Bearer后有空格
            httpPost.setEntity(new StringEntity(params,HTTP.UTF_8));

            long startTime = System.currentTimeMillis();
            response = client.execute(httpPost);
            long endTime = System.currentTimeMillis();
            long t = endTime - startTime;
//			log.info("url="+url+" 耗时 过长： " + t  + "毫秒");
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK
                    || response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
                entity = response.getEntity();
                String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
                return returnStr;
            }else{
                entity = response.getEntity();
                String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
//                log.error("url="+url+",params="+params+",getStatusCode="+response.getStatusLine().getStatusCode());
                log.error("url={},params={},getStatusCode={},returnStr={}", new Object[]{url, params, response.getStatusLine().getStatusCode(),returnStr});
            }
        }finally{
        	try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			httpPost.abort();
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
        }

        return null;
    }
	/**
	 * 上传图片
	 * @param url
	 * @param file
	 * @param params
	 * @return
	 * @throws IOException
	 */
	public static String uploadFile(String url, File file ,Map<String, Object> params) throws IOException {
		log.info("url="+url);
		log.info("params="+params.toString());
		
		HttpPost httpPost = new HttpPost(url);
		httpPost.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		FileBody bin = null;
		if (file != null) {
			bin = new FileBody(file);
		}
		try {
			httpPost.addHeader("Authorization", "uploadFile");
		    MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
		    reqEntity.addPart("file", bin);
		        
			if (params != null && !params.isEmpty()) {
				for (String key : params.keySet()) {
					StringBody comment = new StringBody(params.get(key).toString(), ContentType.TEXT_PLAIN);
					reqEntity.addPart(key, comment);
				}
			}
		    httpPost.setEntity(reqEntity.build());
		    
			response = client.execute(httpPost);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}else{
				log.error("getStatusCode="+response.getStatusLine().getStatusCode());
			}
		}finally{
			try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			httpPost.abort();
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		
		return null;
	}
	
	/**
	 * 项目间调用
	 * @param url
	 * @param userToken
	 * @param params
	 * @return
	 * @throws IOException
	 */
	public static String doPost(String url, String userToken,Map<String, Object> params) throws IOException {
		log.info("url="+url);
		log.info("params="+params.toString());
		
		HttpPost httpPost = new HttpPost(url);
		httpPost.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
	
		try {
			httpPost.addHeader("Authorization", userToken);
		    MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
		        
			if (params != null && !params.isEmpty()) {
				for (String key : params.keySet()) {
					StringBody comment = new StringBody(params.get(key).toString(), ContentType.TEXT_PLAIN);
					reqEntity.addPart(key, comment);
				}
			}
		    httpPost.setEntity(reqEntity.build());
		    
			response = client.execute(httpPost);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}else{
				log.error("getStatusCode="+response.getStatusLine().getStatusCode());
			}
		}finally{
			try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			httpPost.abort();
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		
		return null;
	}
	
	
	public static String doGet(String url) throws IOException {
		HttpGet httpGet = new HttpGet(url);
		httpGet.setConfig(requestConfig);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		try {
			response = client.execute(httpGet);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				EntityUtils.consume(entity);
				return returnStr;
			}
		}finally{
			try {
				EntityUtils.consume(entity);
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}

		return null;
	}
	

	
	public static String doSSL(String url,Map<String, Object> params) throws IOException {

		HttpPost httpPost = new HttpPost(url);
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		DefaultHttpClient httpClient = null;
		try {
			httpClient = new SSLClient();
			//参数
			   List <NameValuePair> nameValuePair = new ArrayList<NameValuePair>();  
				if (params != null && !params.isEmpty()) {
					for (String key : params.keySet()) {
						nameValuePair.add(new BasicNameValuePair(key, params.get(key).toString()));
					}
				}
			    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair,HTTP.UTF_8));  
			
			
			response = httpClient.execute(httpPost);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				EntityUtils.consume(entity);
				return returnStr;
			}
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}finally{
			EntityUtils.consume(entity);
			if(response!=null){
				response.close();
			}
			httpClient.close();
		}

		return null;
	}

	public static String doGet(String url,Map<String, Object> parametersMap) throws ClientProtocolException, IOException {
		
		if (parametersMap!=null){
			StringBuffer parameters = new StringBuffer();
			int i = 0;
			for (String key : parametersMap.keySet()) {
				if (i == 0){
					parameters.append("?");
				}else{
					parameters.append("&");
				}
				parameters.append(key);
				parameters.append("=");
				//ggf updat start
				Object obj=parametersMap.get(key);
				if(obj==null){
					obj="";
				}
				parameters.append(encoding(obj.toString(),"UTF-8"));
				//ggf updat end
				i++;
			}
			url = url + parameters.toString();
		}
//		log.info("url="+url);
		HttpGet httpGet = new HttpGet(url);
		httpGet.setConfig(requestConfig);
		HttpEntity entity = null;
		try {
			CloseableHttpResponse response = client.execute(httpGet);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				String returnStr = EntityUtils.toString(entity, HTTP.UTF_8);
				return returnStr;
			}
		}finally{
			EntityUtils.consume(entity);
//			httpGet.abort();
		}
	
		return null;
	}

	public static String convertStreamToString(InputStream is) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();
		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}
		}catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
		}

		return sb.toString();

	}

	private static String encoding(String content, String encoding) {
		if (content != null) {
			try {
				content = URLEncoder.encode(content, encoding);
			} catch (UnsupportedEncodingException e) {
				log.error(e.getMessage(), e);
			}
		}
		return content;
	}

	/**
	 * 去掉url中的路径，留下请求参数部分
	 * 
	 * @param strURL
	 *            url地址
	 * @return url请求参数部分
	 */
	private static String TruncateUrlPage(String strURL) {
		String strAllParam = null;
		String[] arrSplit = null;

		strURL = strURL.trim();

		arrSplit = strURL.split("[?]");
		if (strURL.length() > 1) {
			if (arrSplit.length > 1) {
				if (arrSplit[1] != null) {
					strAllParam = arrSplit[1];
				}
			}
		}

		return strAllParam;
	}

	/**
	 * 解析出url参数中的键值对 如 "index.jsp?Action=del&id=123"，解析出Action:del,id:123存入map中
	 * 
	 * @param URL
	 *            url地址
	 * @return url请求参数部分
	 */
	public static Map<String, String> urlRequest(String URL) {
		Map<String, String> mapRequest = new HashMap<String, String>();

		String[] arrSplit = null;

		String strUrlParam = TruncateUrlPage(URL);
		if (strUrlParam == null) {
			return mapRequest;
		}
		// 每个键值为一组
		arrSplit = strUrlParam.split("[&]");
		for (String strSplit : arrSplit) {
			String[] arrSplitEqual = null;
			arrSplitEqual = strSplit.split("[=]");

			// 解析出键值
			if (arrSplitEqual.length > 1) {
				// 正确解析
				mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);

			} else {
				if (!arrSplitEqual[0].equals("")) {
					// 只有参数没有值，不加入
					mapRequest.put(arrSplitEqual[0], "");
				}
			}
		}
		return mapRequest;
	}
	
	/**
	 * 加入认证header
	 * @param httpMethodEntity
	 * @param token
	 */
	private void applyAuthentication(HttpRequestBase httpMethodEntity, String token){
		httpMethodEntity.addHeader("Authorization", token);
	}
	
	
/**
 * 这个线程负责使用连接管理器清空失效连接和过长连接
 * @author litianyi
 *
 * 2016年1月5日
 */
static class IdleConnectionMonitorThread extends Thread {
	    
	    private final HttpClientConnectionManager connMgr;
	    private volatile boolean shutdown;
	    
	    public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
	      super();
	      this.connMgr = connMgr;
	    }
	    @Override
	    public void run() {
	    }
	    
	    public void shutdown() {
	      shutdown = true;
	      synchronized (this) {
	        notifyAll();
	      }
	    }
	  }


public static String postBody(String urlPath, String json) throws IOException {
		OutputStream out = null;
		HttpURLConnection urlConnection = null;
		InputStream inputStream = null;
		String body = null;
		try {
			// Configure and open a connection to the site you will send the
			// request
			URL url = new URL(urlPath);
			urlConnection = (HttpURLConnection) url.openConnection();
			// 设置doOutput属性为true表示将使用此urlConnection写入数据
			urlConnection.setDoOutput(true);
			// 定义待写入数据的内容类型，我们设置为application/x-www-form-urlencoded类型
			urlConnection.setRequestProperty("content-type","text/html");
			urlConnection.setRequestProperty("charset", "UTF-8");
			// 得到请求的输出流对象
			out = urlConnection.getOutputStream();
			// 把数据写入请求的Body
			out.write(json.getBytes("UTF-8"));
			out.flush();
			out.close();

			// 从服务器读取响应
			inputStream = urlConnection.getInputStream();
			String encoding = urlConnection.getContentEncoding();
			body = IOUtils.toString(inputStream, encoding);
			
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (urlConnection != null) {
				urlConnection.disconnect();
			}
			if (inputStream != null) {
				inputStream.close();
			}
		}
		return body;
}

	public static String postJson(String urlPath, String json) throws IOException {
		OutputStream out = null;
		HttpURLConnection urlConnection = null;
		InputStream inputStream = null;
		String body = null;
		try {
			// Configure and open a connection to the site you will send the
			// request
			URL url = new URL(urlPath);
			urlConnection = (HttpURLConnection) url.openConnection();
			// 设置doOutput属性为true表示将使用此urlConnection写入数据
			urlConnection.setDoOutput(true);
			// 定义待写入数据的内容类型，我们设置为application/x-www-form-urlencoded类型
			urlConnection.setRequestProperty("content-type","application/json");
			urlConnection.setRequestProperty("charset", "UTF-8");
			// 得到请求的输出流对象
			out = urlConnection.getOutputStream();
			// 把数据写入请求的Body
			out.write(json.getBytes("UTF-8"));
			out.flush();
			out.close();

			// 从服务器读取响应
			inputStream = urlConnection.getInputStream();
			String encoding = urlConnection.getContentEncoding();
			body = IOUtils.toString(inputStream, encoding);
			
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (urlConnection != null) {
				urlConnection.disconnect();
			}
			if (inputStream != null) {
				inputStream.close();
			}
		}
		return body;
	}
	
	/**
	 * 7moor
	 * @param urlPath
	 * @param json
	 * @param authorization
	 * @return
	 * @throws IOException
	 */
	public static String postJson(String urlPath, String json, String authorization) throws IOException {
		OutputStream out = null;
		HttpURLConnection urlConnection = null;
		InputStream inputStream = null;
		String body = null;
		try {
			// Configure and open a connection to the site you will send the
			// request
			URL url = new URL(urlPath);
			urlConnection = (HttpURLConnection) url.openConnection();
			// 设置doOutput属性为true表示将使用此urlConnection写入数据
			urlConnection.setDoOutput(true);
			// 定义待写入数据的内容类型，我们设置为application/x-www-form-urlencoded类型
			urlConnection.setRequestProperty("content-type","application/json");
			urlConnection.setRequestProperty("charset", "UTF-8");
			urlConnection.setRequestProperty("Authorization", authorization);
			// 得到请求的输出流对象
			out = urlConnection.getOutputStream();
			// 把数据写入请求的Body
			out.write(json.getBytes("UTF-8"));
			out.flush();
			out.close();
			
			// 从服务器读取响应
			inputStream = urlConnection.getInputStream();
			String encoding = urlConnection.getContentEncoding();
			body = IOUtils.toString(inputStream, encoding);
			
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
			if (urlConnection != null) {
				urlConnection.disconnect();
			}
			if (inputStream != null) {
				inputStream.close();
			}
		}
		return body;
	}

	public static void main(String[] args) throws ClientProtocolException, IOException, URISyntaxException {
		// dfs文件上传功能
//		String url = "http://211.152.7.181:6333/orderUpload.json";
 		String url = "http://localhost:8081/orderUpload.json";
		File file = new File("F:/GoFun/testFile/slide3.png");
		int i = 1000;
//		while (i >= 0) {
			Map<String, Object> params = new HashMap<String, Object>();
			String orderId = UUIDUtils.uuid();
			System.out.println("orderId生成:"+orderId);
			params.put("orderId", orderId);
			String resultStr = uploadFile(url,file,params);
			System.out.println("控制器返回值:"+resultStr);
			i--;
//		}
/*		// user单文件上传
		String userUrl = "http://211.152.7.181:6333/upload.json";
		File file = new File("F:/GoFun/testFile/slide1.jpg");
		Map<String, Object> params = new HashMap<String, Object>();
		String sim = "13311111111";
		System.out.println("手机号:"+sim);
		params.put("sim", sim);
		String resultStr = uploadFile(userUrl,file,params);
		System.out.println("控制器返回值:"+resultStr);*/
		// dfs单文件删除功能
//		String delurl = "http://211.152.7.181:6333/dfsDelete/deleteOrderImg.json";
// 		String delurl = "http://localhost:8081/dfsDelete/deleteOrderImg.json";
//		Map<String, Object> parametersMap = new HashMap<>();
//		parametersMap.put("groupName", "group1");
//		parametersMap.put("remoteFileName", "/M00/00/03/wKgKMVmLCcOALJ9AAAT13TIUOy0018.jpg");
//		List<String> list = new ArrayList<>();
//		list.add("http://211.152.7.181:6300/group1/M00/0A/1F/wKgKMVmNLQmAXIlFAAD7uZ0pYz8961.jpg");
//		list.add("http://211.152.7.181:6300/group1/M00/0A/1F/wKgKMVmNLU-AGyMfAAT13TIUOy0411.jpg");
//		parametersMap.put("pathList", list);
//		String delresult = doGet(delurl, parametersMap);
//		System.out.println("文件删除结果:" + delresult);
		
		
//		System.out.println(doGet("http://tip.tv.sohu.com/s?ott=17&key=%E7%88%B8"));
//		System.out.println(doPost("http://tip.tv.sohu.com/s?ott=17&key=%E7%88%B8"));
//		System.out.println(doSSL("https://test.api.shouqiev.net/app/setting.json",null));
//		String json = "[{CarNo:\"Q6T1K8\",EngineNo:\"AAPEGL13454\",VIN:\"LVVDB17B3GB118721\",SystemCode:\"06\"}]";
////			postBody("http://test.api.shouqiev.net/etcp/post.json",json);
//		String resultStr = postJson("http://101.201.69.112:8085/Api/CarViolationApi/PostAddCarInventory?Appid=81D8F3A5-7264-4B7A-9D58-D51FA2FF30F7",json);
//		System.out.println(resultStr);
		//System.out.println(MD5.getMD5("{\"parkName\":\"北京一号停车场\",\"parkFee\":10,\"time\":\"2016-05-24 07:53:03\",\"type\":1,\"plateNumber\":\"京Q2PK69\"}"+"0af9f16a69aa34579821ecfd236c4426"));
		
	}
}
